package com.fighYo.trace.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fighYo.trace.entity.User;
import com.fighYo.trace.entity.query.UserQuery;
import com.fighYo.trace.entity.vo.UserVo;
import com.fighYo.trace.mapper.UserMapper;
import com.fighYo.trace.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fighYo
 * @since 2022-04-04
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User getUser(User user) {
        String username = user.getUserName();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", username);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public IPage<UserVo> getUserPageList(Long cur, Long limit, UserQuery userQuery) {
        IPage<UserVo> page = new Page<>(cur, limit);
        IPage<UserVo> userVoIPage = baseMapper.getUserPageList(page, userQuery);
        return userVoIPage;
    }

    @Override
    public UserVo getUserAndInfo(String id) {
        UserVo userAndInfo = baseMapper.getUserAndInfo(id);
        return userAndInfo;
    }

}
